package com.android.zweibo.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.android.zweibo.bean.UserInfo;
import com.android.zweibo.ui.R;

public class UserListAdapter extends BaseAdapter implements ListAdapter {
	private Context context;
    private List<UserInfo> userList;
    private LayoutInflater inflater;
	public UserListAdapter(Context context, List<UserInfo> userList) {
		this.context = context;
		this.userList = userList;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return userList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return userList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return Long.parseLong(userList.get(position).getUserId());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = inflater.inflate(R.layout.users_list_item, null);
		ImageView icon = (ImageView) convertView.findViewById(R.id.users_list_icon);
		TextView  nameText = (TextView) convertView.findViewById(R.id.users_list_name);
		icon.setImageDrawable(userList.get(position).getUserIcon());
		nameText.setText(userList.get(position).getUserName());
		return convertView;
	}

}
